@echo off
chcp 65001 > nul
setlocal

set vbsFile=%temp%\yufei_create_short_cut.vbs

set link=%~1
set file=%~2

if "%file%"=="" ( 
    REM echo file is not set
    echo 文件路径未设置
    exit /b 1
)
if not exist "%file%" ( 
    REM echo [%file%] not exist
    echo %file% 不存在，请输入正确路径
    exit /b 2
)

if "%link%"=="" (
    REM echo shortcut link is not set
    echo 快捷方式路径未设置
    exit /b 3
)

call:createVbs "%file%" "%link%"
if %errorlevel%==0 (
    cscript.exe //nologo "%vbsFile%"
    if exist "%vbsFile%" (
        del /f "%vbsFile%" 
    )
    exit /b 0
) else (
    echo 创建快捷方式出错
    exit /b 1
)
 
:createVbs
echo Set WS=WScript.CreateObject("WScript.Shell") > "%vbsFile%"
echo Set Shortcut=WS.CreateShortCut("%~2.lnk") >> "%vbsFile%"
echo Shortcut.TargetPath="%~1" >> "%vbsFile%"
echo Shortcut.WorkingDirectory="%~dp1" >> "%vbsFile%"
echo Shortcut.Save >> "%vbsFile%"
exit /b 0

